package edu.scu.declaresys.web.util;

import javax.servlet.http.HttpSession;

import edu.scu.declaresys.config.IActionName;
import edu.scu.declaresys.vo.Area;
import edu.scu.declaresys.vo.Project;
import edu.scu.declaresys.vo.User;

/**
 * 
 * @author: zt
 * @since : 2013-7-9
 */
public class DynamicHtmlMaker
{
	/**
	 * 根据用户是否登陆，生成页眉欢迎信息
	 *@param session
	 *@return
	 */
	public static String loginInfo(HttpSession session)
	{
		User user = (User)session.getAttribute(User.T_TABLE);
		//
		StringBuffer sb = new StringBuffer();
		sb.append("<span class=\"login_style\">");
		boolean isLogin = false;
		if(user != null && user.getLoginName() != null)
		{
			isLogin = true;
			sb.append(user.getLoginName()).append("，");
		}
		sb.append("欢迎来到两资申报系统，");
		if(isLogin)
		{
			sb.append("<a href=\"logout.action\">注销</a>");
		}
		else
		{
			sb.append("<a href=\"login.jsp\">登录</a>");
		}
		sb.append("</span>");
		
		return sb.toString();
	}

	public static String rcmdMyRcmdedOperation(HttpSession session, Project project)
	{
		User user = (User)session.getAttribute(User.T_TABLE);
		StringBuffer sb = new StringBuffer();
		int id = project.getId();
		//查看
		sb.append("<a href=\"").append(IActionName.GENERAL_VIEW_PROJECT).append("?").append(Project.T_ID).append("=").append(id).append("\">查看</a>");
		
		int state = project.getState();
		// 修改
		if(state != Project.STATE_UNAUDIT_MODIFIABLE
				&& state != Project.STATE_UNAUDIT_UNMODIFIABLE
				&& state != Project.STATE_REQUEST_MODIFY
				&& state != Project.STATE_PASSED
				&& state != Project.STATE_REJECTED)
		{
			sb.append("<a href=\"").
			append(IActionName.GENERAL_SHOW_PROJECT_FOR_MODIFY).append("?").append(Project.T_ID).append("=").append(id)
			.append("\">&nbsp;|&nbsp修改</a>");
		}
		// 取消推荐
		int level = user.getLevel();
		boolean hasCancelRcmd = (level == Area.LEVEL_COUNTY && state == Project.STATE_UNRCMD_CITY)
							|| (level == Area.LEVEL_CITY && state == Project.STATE_UNRCMD_PROVINCE);
		if(hasCancelRcmd)
		{
			sb.append("<a href=\"").
			append(IActionName.RCMD_REQUEST_CANCEL_RCMD).append("?").append(Project.T_ID).append("=").append(id)
			.append("\">&nbsp;|&nbsp请求取消推荐</a>");
		}
		return sb.toString();		
	}

	public static String rcmdDealCancelRcmdOperation(Project project)
	{
		StringBuffer sb = new StringBuffer();
		Integer id = project.getId();
		sb.append("<a href=\"").append(IActionName.RCMD_DEAL_CANCEL_RCMD_CONFIRM).append("?").append(Project.T_ID).append("=").append(id).append("\">同意</a>");
		sb.append("<a href=\"").append(IActionName.RCMD_DEAL_CANCEL_RCMD_REJECT).append("?").append(Project.T_ID).append("=").append(id).append("\">&nbsp;|&nbsp不同意</a>");
		return sb.toString();
	}
}
